﻿#include "fseditdialog.h"
#include "ui_fseditdialog.h"
#include <QSqlQuery>
QString FSEditDialog::PID;
FSEditDialog::FSEditDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FSEditDialog)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("修改信息状态：");
}

FSEditDialog::~FSEditDialog()
{delete ui;}

void FSEditDialog::receiveID(QString id)
{
    QSqlQuery query;
    QString strSql = QString("select * from FileSbmtPage where FileSbmtID='%1';").arg(id);
    query.exec(strSql);
    if(query.next()){
        PID=query.value(0).toString();
        ui->dtEdtSmtTime->setDate(QDate::fromString(query.value(1).toString(),"yyyy-MM-dd"));
        ui->edtSmtUnit->setText(query.value(2).toString());
        ui->edtSignPeople->setText(query.value(3).toString());
        ui->dtEdtSignTime->setDate(QDate::fromString(query.value(4).toString(),"yyyy-MM-dd"));
        ui->edtDuringPeople->setText(query.value(5).toString());
        ui->edtTel->setText(query.value(6).toString());
        ui->txtQuestion->setText(query.value(7).toString());
        ui->txtSuggestion->setText(query.value(8).toString());
    }
}

void FSEditDialog::on_btnOk_clicked()
{
    strSbmTime = ui->dtEdtSmtTime->date().toString("yyyy-MM-dd");//报送时间
    strSbtUnit = ui->edtSmtUnit->text();//报送单位
    strSignTime = ui->dtEdtSignTime->date().toString("yyyy-MM-dd");//签发时间
    strSignPeople = ui->edtSignPeople->text();//签发人
    strDuringPeople = ui->edtDuringPeople->text();//经办人
    strTel = ui->edtTel->text();//联系电话
    strQuestion = ui->txtQuestion->toPlainText();
    strSuggestion = ui->txtSuggestion->toPlainText();

    const char *s = strTel.toUtf8().data();
    while(*s && *s>='0' && *s<='9')s++;//bool(*s)返回false为数字

    if(strSbtUnit.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入报送单位！");
    }else if(strSbtUnit.size() > 120){//120
        ui->status->setText("修改信息状态：报送单位信息输入有误！");
    }else if(strSignPeople.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入签发人！");
    }else if(strSignPeople.size() > 50){//50
        ui->status->setText("修改信息状态：签发人信息输入有误！");
    }else if(strDuringPeople.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入经办人！");
    }else if(strDuringPeople.size() > 50){//50
        ui->status->setText("修改信息状态：经办人信息输入有误！");
    }else if(strTel.trimmed().isEmpty()){
        ui->status->setText("修改信息状态：请输入联系电话！");
    }else if(bool(*s)){
        ui->status->setText("修改信息状态：联系电话输入有误！");
    }else{
        QString strUpdate=QString("update FileSbmtPage set FileSbmTime = '%1',FileSbmtUnit = '%2',"
                                  "FileSignName = '%3',FileSignTime = '%4',FileDrgName = '%5',"
                                  "FileSbmTel = '%6',FileLvQstn = '%7',FileSignSgstn = '%8'"
                                  "where FileSbmtID = '%9';")
                .arg(strSbmTime).arg(strSbtUnit).arg(strSignPeople).arg(strSignTime)
                .arg(strDuringPeople).arg(strTel).arg(strQuestion).arg(strSuggestion).arg(PID);
        QSqlQuery query;
        if(query.exec(strUpdate)){
            ui->status->setText("修改信息状态：表单信息修改成功！");
            this->close();
        }else{
            ui->status->setText("修改信息状态：表单信息修改失败！");
        }
    }
}

void FSEditDialog::on_btnCancel_clicked()
{
    this->close();
}
